#ifndef LABEL_OBJECT_H
#define LABEL_OBJECT_H

#include "ValueObject.h"
#include "ValueType.h"

#include <object_v2/object_v2.h>

/**
 * @brief LabelObjectEvent 事件枚举
 */
typedef enum _LabelObjectEvent LabelObjectEvent;
enum _LabelObjectEvent
{
        LABEL_OBJECT_EVENT_LEFT,   // 左花括号
        LABEL_OBJECT_EVENT_RIGHT,  // 右花括号
        LABEL_OBJECT_EVENT_ENDL,   // 终止字符'\0'
        LABEL_OBJECT_EVENT_VALUEC, // 数值字符，包括数字、折号'-'
        LABEL_OBJECT_EVENT_COMMA,  // 逗号
        LABEL_OBJECT_EVENT_OTHER
};

typedef enum _LabelObjectState LabelObjectState;
enum _LabelObjectState
{
        LABEL_OBJECT_STATE_START,
        LABEL_OBJECT_STATE_RECV_DEFAULT,
        LABEL_OBJECT_STATE_RECV_DIRECT, // 直接数据，未被花括号包围的内容，包括单个数字、单个日期、文本内容
        LABEL_OBJECT_STATE_REFRESH,
        LABEL_OBJECT_STATE_ENDL,
        LABEL_OBJECT_STATE_EXIT,
        LABEL_OBJECT_STATE_FAILED
};

/**
 * @brief 逗号机，需要判断每个 ValueObject 的 Key 类型是否与 Value 类型相匹配
 */
OBJECT_DECLARE (LabelObject, label_object)
#define LABEL_OBJECT(any) ((LabelObject*)(any))
struct _LabelObject
{
        ObjectNode               parent_instance;
        ValueType                value_type;
        LabelObjectState         label_state;
        ObjectString*            key;

        ObjectStringApplication* cache_for_value;
        ValueObject*             value_head;
};

/**
 * @brief 设置 Label 对象的 Key 值，自动引用对象。
 */
void label_object_set_key (LabelObject* obj, ObjectString* key);
/**
 * @brief 设置 Label 对象的类型。类型从 TopMark 解析中可以取得
 */
void label_object_set_type (LabelObject* obj, ValueType type);
/**
 * @brief 从 Value 字符中分析出 ValueObject，若未先设定
 * ValueType，则将自动解析字符串的 ValueType
 */
int label_object_analysis_value (LabelObject*             obj,
                                 ObjectStringApplication* str_ref);

#endif